 
layui.define(['form','laydate','xmSelect'], function(exports){
	var $ = layui.$
    ,form = layui.form
    ,setter = layui.setter
    ,laydate = layui.laydate
    ,xmSelect = layui.xmSelect;
	var groupSelect = xmSelect.render({
		el: '#groupSelect', 
		autoRow: true,
		name:'pId',
		radio: true,
		clickClose: true,
		tree: {
			show: true,
			showFolderIcon: true,
			showLine: true,
			strict: false,
			indent: 20,
			expandedKeys: [ -1 ],
		},
		height: 'auto',
		on: function(data){
			if(data.isAdd){
				$('#groupSelect').find("input[name=groupId]").val(data.change[0].value);
			}
		}
	});
	$.ajax({
		  url: setter.host+'/adminmanager/group/getTreeSelect'
	      ,type:'post'
	      ,dataType:'json'
	      ,success: function(res){
	        //请求成功后
	    	  if(res.status == setter.response.statusCode.status_Success){
	    		  groupSelect.update({
		      		  data: res.data,
		      		  autoRow: true,
		      	  })
		      	  groupSelect.setValue($('#oldpId').val().split(","));
	    	  }else{
	    		  layer.msg(res.msg);
	    	  }
	      }
	  });
    lay('#createTime').on('click', function(e){ //假设 test1 是一个按钮
    	  laydate.render({
    	    elem: '#createTime'
    	    ,show: true //直接显示
    	    ,closeStop: '#createTime' //这里代表的意思是：点击 test1 所在元素阻止关闭事件冒泡。如果不设定，则无法弹出控件
    	  });
    });
    form.on('select(typeSelect)',function (data){
    	if(data.value=='button'){
    		$('#url').attr('readonly','readonly');
    		$('#url').val('add');
    		$('#menuName1').find("input").val('新增');
	    	$('#menuName1').css('display','none');
	    	$('#menuName2').css('display','block');
    	}else {
    		$('#url').removeAttr('readonly');
    		$('#url').val('');
    		$('#menuName1').find("input").val('');
	    	$('#menuName1').css('display','block');
	    	$('#menuName2').css('display','none');
    	}
    });
    form.on('select(buttonSelect)',function (data){
    	
    	if(data.value=='add'){
    		$('#menuName1').find("input").val('新增');
	    	$('#url').val('add');
	    	$('#name').val('add');
    	}else if(data.value=='edit'){
    		$('#menuName1').find("input").val('编辑');
	    	$('#url').val('edit');
    	}else if(data.value=='batchdel'){
    		$('#menuName1').find("input").val('删除');
	    	$('#url').val('batchdel');
    	}else if(data.value=='export'){
    		$('#menuName1').find("input").val('导出');
	    	$('#url').val('export');
    	}
    });
    $("#about1").mouseover(function() {
    	layer.tips('设置该模块下的可见字段', this);
    });
    var menuId = $('body').find('input[name=menuId]').val();
	layui.admin.req({
        url: setter.host+'/adminmanager/menu/queryMenuField'
        ,type:'post'
        ,contentType: "application/json; charset=utf-8"
        ,data:'{"menuId":"'+menuId+'"}'
        ,done: function(res){
          //请求成功后
          if(res.status == setter.response.statusCode.status_Success){
        	  $('input[name="field"]').val(res.data.field);
          }else{
        	  layer.msg(res.msg);
          }
        }
      });
  //对外暴露的接口
    exports('edit', {});
});